#ifndef MQTTCLIENTMANAGER_H
#define MQTTCLIENTMANAGER_H

#include <QObject>
#include <QString>
#include <QTcpSocket>
#include <QtMqtt/qmqttclient.h>

class MQTTClientManager : public QObject
{
    Q_OBJECT

public:
    /// MQTT管理器无参构造
    explicit MQTTClientManager(QObject *parent = nullptr);
    /// 获取MQTT管理器单例对象地址
    static MQTTClientManager* instance();
    /// MQTT连接
    Q_INVOKABLE bool MQTTConnect();
    /// MQTT发布
    Q_INVOKABLE bool MQTTPublish(const QString &topic, const QString& message, quint16 qos = 0, bool retain = false);
    /// MQTT订阅
    Q_INVOKABLE bool MQTTSubscribe(const QString &topic, quint16 qos = 0);
    /// 设置MQTT Host
    Q_INVOKABLE void setMQTTHost(const QString &host) { mMQTTHost = host; }
    /// 设置MQTT端口
    Q_INVOKABLE void setMQTTPort(quint16 port) { mMQTTPort = port; }
    /// 设置MQTT用户名
    Q_INVOKABLE void setMQTTUserNmae(const QString &usernmae) { mMQTTUserNmae = usernmae; }
    /// 设置MQTT密码
    Q_INVOKABLE void setMQTTPassword(const QString &password) { mMQTTPassword = password; }

private:
    /// MQTT服务IP
    QString mMQTTHost{"120.26.145.47"};
    /// MQTT服务端口号
    quint16 mMQTTPort{1883};
    /// MQTT服务用户名
    QString mMQTTUserNmae{""};
    /// MQTT服务密码
    QString mMQTTPassword{""};
    /// MQTT客户端连接
    QMqttClient *mMQTTClient{nullptr};
};

#endif // MQTTCLIENTMANAGER_H
